package cn.itcast.user.interceptor;


import cn.itcast.hmall.utils.ThreadLocalUtil;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Component
public class myHandlerIntercept implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
        String header = request.getHeader("authorization");
        System.err.println("请求中获得的头信息： "+header);
        if(header!=null){
            Long i=Long.parseLong(header);
            System.out.println(i);
            ThreadLocalUtil.setUserId(i);
            Long userId = ThreadLocalUtil.getUserId();
            return true;}

        System.err.println(header);
        return true;
    }
}
